package Jcat.cduestcbbs.DaoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.List;

import jcat.hbc.connectionpool.HBCConnectionPool;

import Jcat.cduestcbbs.Dao.FriendDao;
import Jcat.cduestcbbs.Po.FriendPo;
import Jcat.cduestcbbs.Po.UserPo;

public class FriendDaoImpl implements FriendDao {

	public boolean deleteFriend(FriendPo friend) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}

	public List<FriendPo> frindQuery() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	public boolean insertFriend(FriendPo friend, UserPo user)
			throws SQLException {

		Connection conn = HBCConnectionPool.getInstance().getConnection();
		Statement st = null;
		st = conn.createStatement();
		int result = st.executeUpdate("insert into friends (My_id,My_friends_id,My_friends_add_time)" +
				"values('"+user.getUserId()+"','"+friend.getMyfriendsId()+"','"+friend.getMyFrindMakeTime()+"')");

		if (result == 1) {
			return true;
		} else {
			return false;
		}
	}
    
	public synchronized boolean selectFriendByCurrentUser(FriendPo friend,
			UserPo user) throws SQLException {

		Connection conn = HBCConnectionPool.getInstance().getConnection();
		Statement st = null;
		st = conn.createStatement();
		boolean result1 = st
				.execute("select * froms fridends where My_id = "
						+ user.getUserId() + "and My_friends_id = "
						+ friend.getMyId());
		boolean result2 = st
		        .execute("select * froms fridends where My_friends_id = "
				        + user.getUserId() + "and My_id = "
				        + friend.getMyId());
		if (result1 == false && result2 == false) {
			return false;
		} else
			return true;
	}

	public static void main(String args[]) {
		Connection con = HBCConnectionPool.getInstance().getConnection();
		try {

			StringBuffer sql = new StringBuffer();

			sql.append(("insert into TEST values "));
			for (int j = 1; j <= 100000; j++) {
				sql.append(("(" + j + "),"));
			}
			String sql1 = sql.substring(0, sql.length() - 1);
			Statement stmt = con.createStatement();
			stmt.execute(sql1);

		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {

				con.close();
			} catch (SQLException e) {
				
				e.printStackTrace();
			}
		}

	}

}
